package com.example.voucher.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.voucher.contract.VoucherItemCapable;
import com.example.voucher.contract.spi.VoucherItemCapablePurchaseInvoiceReceiptVerifyAdapter;
import com.example.voucher.entity.InvoiceReceiptVerify;
import com.example.voucher.extension.ExtensionImpl;
import com.example.voucher.mapper.InvoiceReceiptVerifyMapper;
import com.example.voucher.service.PurchaseInvoiceQueryService;
import com.google.common.collect.Lists;

@ExtensionImpl(extendFrom = PurchaseInvoiceQueryService.class, applyTo = {"purchase-invoice-query-service_ReceiptInverify"})
public class PurchaseInvoiceQueryServiceReceiptVerifyImpl implements PurchaseInvoiceQueryService {

    @Autowired
    private InvoiceReceiptVerifyMapper irvMapper;

    @Override
    public List<VoucherItemCapable> queryVoucherItem(List<Long> pkidList) {
        // 组装VoucherItemCapable
        List<VoucherItemCapable> list = Lists.newArrayList();

        // 查询InvoiceReceiptVerify
        LambdaQueryWrapper<InvoiceReceiptVerify> queryWrapper = Wrappers.<InvoiceReceiptVerify>lambdaQuery();
        queryWrapper.in(InvoiceReceiptVerify::getInvoiceId, pkidList);
        List<InvoiceReceiptVerify> irvList = irvMapper.selectList(queryWrapper);
        for (InvoiceReceiptVerify invoiceReceiptVerify : irvList) {
            list.add(new VoucherItemCapablePurchaseInvoiceReceiptVerifyAdapter(invoiceReceiptVerify));
        }

        return list;
    }

}
